/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package autenticacion.Capa_Negocios;
import java.security.MessageDigest;
/**
 * @author Miguel
 */
public class cntEncriptar {
    public cntEncriptar(){}
    private static String hash(String clear) throws Exception {
        MessageDigest md = MessageDigest.getInstance("MD5");
        byte[] b = md.digest(clear.getBytes());
        int size = b.length;
        StringBuffer h = new StringBuffer(size);
        for (int i = 0; i < size; i++) {
            int u = b[i]&255; // unsigned conversion
            if (u<16) {
                h.append("0"+Integer.toHexString(u));
            } else {
                h.append(Integer.toHexString(u));
            }
        }
        return h.toString();
    }
    public static String encriptar(String palabra) throws Exception {
        String pe="";
        try {
            pe = hash(palabra);
        } catch (Exception e) {
            throw new Error("<strong>Error: Al encriptar el password</strong>");
        }
        return pe;
    }
}
